#include "GameOverController.h"

GameOverController::GameOverController(Model *m, View *v, NetworkPat* net): Controller(m, v)
{
  _model = (GameOverModel*)m;
  _view = (GameOverView*)v;
  _net = net;
  newGameState = GameState::GameOver;
  mShouldReset = true;
}

GameOverController::~GameOverController(void)
{
}

void GameOverController::HandleMessages(std::list<Message*> *l)
{
  if(l == NULL)
    return;
  //get messages from the network
  if(mShouldReset)
  {
    _model->mWin = _net->GetWin();
    _net->Reset();
    mShouldReset = false;
  }

  newGameState = GameState::GameOver;
  while(!l->empty())
  {
    Message* temp = l->front();
    l->pop_front();
    if(temp->GetMessageType() == MessageType::USER_INPUT)
    {
      switch(temp->GetMessageContent())
      {
        case GameAction::SELECT:
          newGameState = GameState::MainMenu;
          mShouldReset = true;
          break;
      }
    }
    delete temp;
  }
}

GameState GameOverController::Update(void)
{
  _view->DrawScreen();
  return newGameState;
}

void GameOverController::PassMessage(Message* msg)
{
}

void GameOverController::ProcessMessages(void)
{
}
